<?php

namespace App\Admin\Http\Controllers\Web;

use Flash;
use App\Admin\Eloquent\Users;
use App\Admin\Http\Controllers\Controller;
use App\Extensions\Pagination\BootstrapThreePresenter;
use Illuminate\Http\Request;

class UsersController extends Controller
{
  /**
     * 角色列表信息
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $query = $request->only('search');

        $users = Users::paginateQuery($query);

        // 追加分页查询条件
        if (!empty($query)) {
            $users->appends($query);
        }

        // 分页查询代码
        $links = (new BootstrapThreePresenter($users))->render();

        return view('admin.web.users.index', compact('users', 'query', 'links'));
    }
    /**
     *  展示用户详情
     *
     * @param int $id
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function show(int $id){
        $user = Users::findOrFail($id);

        return view('admin.web.users.show',compact('user'));
    }
    /**
     * 根据导航id删除用户记录
     *
     * @param int $id
     * @return \Illuminate\Http\RedirectResponse
     */
    public function destroy(int $id){
        $navigation = Users::findOrFail($id);

        $navigation->delete();

        Flash::success('删除导航记录成功!');

        return $this->redirectAction('Web\UsersController@index');
    }
}